package com.zhiqingchun.web.mail;

import java.io.UnsupportedEncodingException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.zhiqingchun.dao.account.IUserDao;
import com.zhiqingchun.dao.account.UserResult;
import com.zhiqingchun.pojo.MailDO;

@Controller
@RequestMapping("/newbox.html")
public class NewboxController {

	@RequestMapping(method = RequestMethod.GET)
	public String get(ModelMap map, HttpServletRequest request, HttpServletResponse response,
			int id) {
		UserResult userResult = userDao.byId(id);
		if (userResult.isSuccess()) {
			map.addAttribute("tosb", userResult.getUsr());
		}
		return "mail/newbox";
	}
	
	@RequestMapping(method = RequestMethod.POST)
	public String post(ModelMap map, HttpServletRequest request, HttpServletResponse response) {
		try {
			request.setCharacterEncoding("utf-8") ;
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		
		return "redirect:user.html?id=";// + mailDO.getTosb();
	}
	
	@Autowired
	private IUserDao userDao;

	public IUserDao getUserDao() {
		return userDao;
	}

	public void setUserDao(IUserDao userDao) {
		this.userDao = userDao;
	}
}
